package com.weipai.springboot.module.dao.impl;

import com.weipai.springboot.model.Product;
import com.weipai.springboot.model.ProductDesc;
import com.weipai.springboot.model.ProductPro;
import com.weipai.springboot.model.Role;
import com.weipai.springboot.module.dao.ProductDao;
import com.weipai.springboot.module.mapper.ProductDescMapper;
import com.weipai.springboot.module.mapper.ProductMapper;
import com.weipai.springboot.module.mapper.ProductProMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @Author: 曹朋飞
 * @Date: 2018/08/23 18:35
 */
@Repository
public class ProductDaoImpl implements ProductDao{

    @Autowired
    ProductMapper productMapper;
    @Autowired
    ProductDescMapper productDescMapper;
    @Autowired
    ProductProMapper productProMapper;
    
    @Override
    public int save(Product product) {
        return productMapper.insertSelective(product);
    }

    //分页查询
    @Override
    public List<Map<String, Object>> selectAllProductByPage(Integer start, Integer end, String productCategoryId, Integer isAudit,
                                                            String search) {
        return productMapper.selectAllProductByPage(start, end, productCategoryId, isAudit, search);
    }

    //分页查询莫一分类的所有商品数量
    @Override
    public Integer selectAllProductByPageAmount(String productCategoryId, Integer isAudit,
                                                String search) {
        return productMapper.selectAllProductByPageAmount(productCategoryId, isAudit, search);
    }

    //修改商品的第一个页面
    @Override
    public Map<String, Object> getProductInfoById01(String id) {
        return productMapper.getProductInfoById01(id);
    }

    //保存商品详情
    @Override
    public int saveProductDesc(ProductDesc productDesc) {
        return productDescMapper.insertSelective(productDesc);
    }

    //更新货品
    @Override
    public int updateProduct(String productId, String productName, String productSpec) {
        return productMapper.updateProduct(productId, productName, productSpec);
    }

    //更改详情和图片
    @Override
    public int updateProductDesc(ProductDesc productDesc) {
        return productDescMapper.updateByPrimaryKeySelective(productDesc);
    }

    //通过spuNumber查询货品
    @Override
    public Map<String, String> getProductBySpuNumber(String spuNumber) {
        return productMapper.getProductBySpuNumber(spuNumber);
    }

    //查出货品的详情和图片
    @Override
    public Map<String, Object> getProductImgAndDescBySpuNumber(String spuNumber) {
        return productMapper.getProductImgAndDescBySpuNumber(spuNumber);
    }

    //得到最大产品编号的数据
    @Override
    public Map<String, Object> getMaxSpuNumberFlag() {
        return productMapper.getMaxSpuNumberFlag();
    }

    //产品审核
    @Override
    public int changeIsAudit(String id, Integer status) {
        return productMapper.changeIsAudit(id, status);
    }

    @Override
    public Product selectByPrimaryKey(String productId) {
        return productMapper.selectByPrimaryKey(productId);
    }

    @Override
    public int updateByPrimaryKeySelective(Product product) {
        return productMapper.updateByPrimaryKeySelective(product);
    }

    @Override
    public int updateStatus(String spuNumber, Integer status) {
        return productMapper.updateStatus(spuNumber, status);
    }

    //删除产品
    @Override
    public int deleteProductBySpuNumber(String spuNumber) {
        return productMapper.deleteProductBySpuNumber(spuNumber);
    }

    //查询产品的数量
    @Override
    public int getProductAmount(int status) {
        return productMapper.getProductAmount(status);
    }

    @Override
    public Integer getEvaluateAmount() {
        return productMapper.getEvaluateAmount();
    }

    @Override
    public void saveProductPro(List<ProductPro> proList) {
        int size01 = proList.size();
        for(int i=0;i<size01;i++){
            productProMapper.insert(proList.get(i));
        }
    }

    @Override
    public Map<String, Object> getMaxSpuNumber() {
        return productMapper.getMaxSpuNumber();
    }
}
